using System;
using System.ComponentModel;
using System.Transactions;
using System.Data;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The TimeTableManager class is responsible for managing BO.TimeTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class TimeTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all TimeTable objects in the database.
        /// </summary>
        /// <returns>A list with all TimeTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static TimeTableList GetList()
        {
            return TimeTableDB.GetList();
        }

        /// <summary>
        /// Gets a single TimeTable from the database without its data.
        /// </summary>
        /// <param name="timeTableKey">The TimeTableKey of the TimeTable in the database.</param>
        /// <returns>A TimeTable object when the TimeTableKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static TimeTable GetItem(int timeTableKey)
        {
            return GetItem(timeTableKey, false);
        }

        /// <summary>
        /// Gets a single TimeTable from the database.
        /// </summary>
        /// <param name="timeTableKey">The TimeTableKey of the TimeTable in the database.</param>
        /// <param name="getTimeTableRecords">Determines whether to load all associated TimeTable records as well.</param>
        /// <returns>
        /// A TimeTable object when the TimeTableKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static TimeTable GetItem(int timeTableKey, bool getTimeTableRecords)
        {
            TimeTable myTimeTable = TimeTableDB.GetItem(timeTableKey);
            return myTimeTable;
        }

        public static DataTable GetItemTable(int timeTableKey)
        {
            return TimeTableDB.GetItemTable(timeTableKey);
        }

        /// <summary>
        /// Saves a TimeTable in the database.
        /// </summary>
        /// <param name="myTimeTable">The TimeTable instance to save.</param>
        /// <returns>The new TimeTableKey if the TimeTable is new in the database or the existing TimeTableKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(TimeTable myTimeTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int timeTableTimeTableKey = TimeTableDB.Save(myTimeTable);

                //  Assign the TimeTable its new (or existing TimeTableKey).
                myTimeTable.TimeTableKey = timeTableTimeTableKey;

                myTransactionScope.Complete();

                return timeTableTimeTableKey;
            }
        }

        /// <summary>
        /// Deletes a TimeTable from the database.
        /// </summary>
        /// <param name="myTimeTable">The TimeTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(TimeTable myTimeTable)
        {
            return TimeTableDB.Delete(myTimeTable.TimeTableKey);
        }

        /// <summary>
        /// Deletes a TimeTable from the database.
        /// </summary>
        /// <param name="myTimeTable">The TimeTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(int timeTableKey)
        {
            return TimeTableDB.Delete(timeTableKey);
        }

        #endregion

    }

}
